﻿using CPPEI.Coolzon.Designtime.Metadata;
using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Designer.Views
{
    public partial class SceneWindow
    {
        [Common.Subscribe]
        public void OnEndGetSolutionListEvent(Event.NCL.EndGetLatestVersiontEvent @event)
        {
            this.Dispatcher.Invoke(() =>
            {
                this.IsEnabled = true;
            });

            if (@event.State == Event.NCL.NCLEventState.Finished)
            {
                ServiceProxy.DesignServiceRef.GetLatestVersionResponse response = @event.LatestVersion;
                this.Dispatcher.Invoke(() =>
                {
                    VSFile vsFile = VSFileMgr.GetFile(UIContext.Current.LocalWorkSpace.LocalPath, UIContext.Current.CurrentSolution.ID, UIContext.Current.CurrentSolution.ID);
                    if (vsFile == null || response.ItemVersion > vsFile.Version)
                    {
                        CustomMessageBox.ShowError("服务器存在新版本，请获取！");
                    }
                    else
                    {
                        BeginCreateScene();
                    }
                });
            }
            else if (@event.State == Event.NCL.NCLEventState.Failure)
            {
                CustomMessageBox.ShowError("场景创建失败！");
            }
        }
    }
}
